package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTradeMarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 里
 */
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTradeMarkController {
    @Autowired
    private BaseTradeMarkService baseTradeMarkService;

    @GetMapping("/{page}/{limit}")
    public Result getBaseTradeMarkPage(@PathVariable Long page,@PathVariable Long limit){
        Page<BaseTrademark> baseTradeMarkPage = new Page(page,limit);
        IPage iPage =  baseTradeMarkService.getBaseTradeMarkPage(baseTradeMarkPage);
        //返回数据
        return Result.ok(iPage);
    }

    //保存数据
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTradeMarkService.save(baseTrademark);
        return Result.ok();
    }

    // 删除
    @DeleteMapping("/remove/{id}")
    public Result removeById(@PathVariable Long id){
        baseTradeMarkService.removeById(id);
        return Result.ok();
    }

    //修改
    //根据品牌id来获取品牌数据
    @GetMapping("/get/{id}")
    public Result getBaseTrademarkById(@PathVariable String id){
        //根据品牌id来获取品牌数据
        BaseTrademark baseTrademark = baseTradeMarkService.getById(id);
        //将获取到的数据返回给前端页面
        return Result.ok(baseTrademark);
    }

    @PutMapping("/update")
    public Result update( @RequestBody BaseTrademark baseTrademark){
        //更新
        baseTradeMarkService.updateById(baseTrademark);
        //返回数据
        return Result.ok();
    }

}
